﻿Ext.define('Roy.controller.main.MainController', {
    extend: 'Ext.app.Controller',

    requires: ['Roy.view.main.Menu'],
    refs: [{
        ref: 'mainMenu',
        selector: 'main_menu'
    }],

    init: function () {
        this.control({
            'main_menu #systemManage': {
                itemclick: this.myTaskOpen
            },
            'main_menu #logManage': {
                itemclick: this.myTaskOpen
            }
        });
    },

    // 打开新的tab
    myTaskOpen: function (e, record) {
        if (record.data.leaf) {
            var idName = "taskTab" + record.data.id;
            var panel = Ext.get(idName);
            var main = Ext.getCmp("content-panel");
            //alert(record.data.qtitle);
            if (!Ext.isEmpty(panel)) {
                panel = Ext.getCmp(idName);
                main.setActiveTab(panel);
            } else {
                var panel = {
                    title: record.data.text,
                    id: idName,
                    layout: { type: 'border' },
                    items: [
                            Ext.create(record.data.qtitle, {
                                region: 'center',
                                margins: '5 5 5 5'
                            })
                    ],
                    closable: true
                };

                var p = main.add(panel);
                main.setActiveTab(p);
            }
        }
        e.stopEvent;
    },
    openTab: function (panel) {
        var main = Ext.getCmp("content-panel");
        var p = main.add(panel);
        main.setActiveTab(p);
    }
})
